*** Settings ***
Library           Selenium2Library
Resource          ../CommonOpreators/OpProposal/OpMotor.robot
Resource          ../CommonOpreators/OpLogin.robot
Resource          ../CommonVars/ComLoginfo/loginfos.robot    # 登录数据
Resource          ../CommonOpreators/OpLogin.robot    # 登录操作关键字
Resource          ../CommonVars/Locations/SITSYS/MoudleView/LLoginView.robot    # 登录页面定位信息
Resource          ../CommonOpreators/MenuOpreator/OpPropsoalMenu.robot    # 投保菜单管理操作
Resource          ../CommonVars/Locations/SITSYS/MoudleView/LMenuView/LMenuVIew.robot    # 投保菜单管理定位信息
Resource          ../CommonOpreators/OpQuotationSales/OpDirectSalesBusinessMode.robot    # 销售信息页面操作
Resource          ../CommonVars/Locations/SITSYS/MoudleView/LQuotationSalesView/LQutationSalesView.robot    # 销售信息
Resource          ../CommonVars/DataVariables/VCodeNames/VConfers.robot    # 其他业务 含 机构 \ 渠道代理 业务员
Resource          ../CommonOpreators/OpProposal/OpOwner.robot    # 车主
Resource          ../CommonVars/DataVariables/VOwner.robot    # 车主
Resource          ../CommonOpreators/OpProposal/OpMotor.robot    # 车辆信息
Resource          ../CommonOpreators/OpProposal/OpRisk/OpBzRisk/OpBzRiskPaytaxes.robot    # 交强险
Resource          ../CommonOpreators/OpProposal/OpRisk/OpBsRisk/OpBsRiskMainRisk/OpBsRisk.robot    # 商业险
Resource          ../CommonOpreators/OpProposal/OpRelationPart/OpAppliRelationPart/OpAppliReationPart.robot    # 投保人
Resource          ../CommonOpreators/OpProposal/OpFloatButtonPart/Op 按钮点击后.robot    # 报价
Resource          ../CommonOpreators/OpProposal/OpRelationPart/OpAppliRelationPart/OpInsureRelationPart/OpInsureRelationPart.robot
Resource          ../CommonOpreators/OpUwSys/核保子系统.robot
Resource          TsDiffConBensTypes.robot
Library           ../CommonLibs/SeleniumUtils/CustomSeleniumLibrary.py
Resource          ../CommonOpreators/OpFinSys/OpFinSys.robot
Resource          ../CommonOpreators/批改/Op批改类型.robot

*** Keywords ***
PersonCompany
    [Arguments]    ${companycode}    ${Salesman}    ${riskcode}    ${car}    ${PersonGroup}    ${产品}    ${是否两地车}
    Op 投保单菜单单击后    1    # 1 表示为新增报价
    Go DirectSales Business Mode    ${companycode}    ${Salesman}    NONE    1    NONE    NONE    ${产品}
    BaseProposal    ${PersonGroup}    ${是否两地车}    ${car}    ${riskcode}

Bs Risk Type
    [Arguments]    ${code}    ${是否两地车}
    ${len}=    Get Length    ${proposalnolist}
    ${keys}=    Get Dictionary Keys    ${proposalnolist}
    ${values}=    Get Dictionary Values    ${proposalnolist}
    FOR    ${var}    IN RANGE    0    ${len}
        ${pdcode}=    run keyword if    '产品代码' ==${keys}[${var}]    set variable    ${values}[${var}]
        exit for loop if    '产品代码' ==${keys}[${var}]
    END
    run keyword if    '${pdcode}' in '0317'    On Bs Check Flag 0317
    ...    ELSE    On Bs Check Flag
    # 断平台
    run keyword if    '${是否两地车}' \ == '两地车' and \ '${pdcode}' in '0317'    Select Checkbox    ${L0317断平台check}
    ...    ELSE IF    '${是否两地车}' \ == '两地车' and \ '${pdcode}' in '0312'    Select Checkbox    ${L0312断平台check}
    run keyword if    '${code}' in '030101'    Op Bs Risk Only 030101
    ...    ELSE IF    '${code}' in '030102'    Op Bs Risk Only 030102
    ...    ELSE IF    '${code}' in '030104'    Op Bs Risk Only 030104
    ...    ELSE IF    '${code}' in '0301045'    Op Bs Risk Only 030104_030105
    ...    ELSE IF    '主险' in '${code}' and '附加险' not in '${code}'    Op Bs Risk Only 主险
    ...    ELSE IF    '主险附加险' in '${code}'    主险附加险    ${pdcode}
    ...    ELSE    Op Bs Risk Only 主险
    Op Yanche

PersonGroupRelation
    [Arguments]    ${TypeCode}    ${RealtionPartType}    ${BusinessCode}
    ${name}=    Get Dictionary Keys    ${VRelationCodeName}
    ${len}=    Get length    ${name}
    ${num}=    evaluate    ${len}-10
    ${varappli}=    evaluate    random.randint(0, ${num})
    ${varappsure}=    evaluate    random.randint(0, ${num})
    run keyword if    ${TypeCode} == ${VTypeCode}[1]    Run keywords    AppliRelation    ${TypeCode}    ${name}[${varappli}]    ${RealtionPartType}    ${BusinessCode}
    ...    AND    InsureRelation    ${TypeCode}    ${name}[${varappsure}]    ${RealtionPartType}    ${BusinessCode}
    ...    ELSE    Run keywords    AppliRelation    ${TypeCode}    None    ${RealtionPartType}    ${BusinessCode}
    ...    AND    InsureRelation    ${TypeCode}    None    ${RealtionPartType}    ${BusinessCode}

AppliRelation
    [Arguments]    ${TypeCode}    ${RealtionPartType}    ${name}    ${BusinessCode}
    [Documentation]    投保人
    Op Appli Relation Person    ${TypeCode}    ${RealtionPartType}    ${name}    ${BusinessCode}

InsureRelation
    [Arguments]    ${TypeCode}    ${RealtionPartType}    ${name}    ${BusinessCode}
    [Documentation]    被保险人
    Op Insure Relation Part    ${TypeCode}    ${RealtionPartType}    ${name}    ${BusinessCode}

PersonGroupOwner
    [Arguments]    ${TypeCode}    ${MotorPartType}
    ${name}=    Get Dictionary Keys    ${VRelationCodeName}
    ${len}=    Get length    ${name}
    ${num}=    evaluate    ${len}-10
    ${var}=    evaluate    random.randint(0, ${num})
    #团单
    ${groupname}    run keyword if    ${TypeCode} == ${VTypeOfOwnerCode}[2]    set variable    ${name}[${var}]
    ...    ELSE    set variable    None
    Op 车主信息    ${TypeCode}    ${MotorPartType}    None    None    15779606784    ${groupname}

CloseWin
    Close All Browsers
    #popen    taskkill /F /im chrome.exe
    #popen    taskkill /F /im chromedriver.exe
    #popen    taskkill /F /im geckodriver.exe
    #popen    taskkill /F /im firefox.exe

UW
    [Arguments]    ${url}    ${username}    ${passwd}    ${proposalnolist}
    [Documentation]    1、登录系统
    ...    2、循环是否待审核-审核中
    ...    3、teardown \ 关闭 Browser
    ...
    ...    解决后台驱动没有关闭
    ${len}=    Get Length    ${proposalnolist}
    ${keys}=    Get Dictionary Keys    ${proposalnolist}
    ${values}=    Get Dictionary Values    ${proposalnolist}
    登录核保系统    ${url}    ${Lusername}    ${username}    ${Lpasswd}    ${passwd}    ${Lsubmit}
    # 一条数据
    FOR    ${var}    IN RANGE    0    ${len}
        run keyword if    '待核保审核' in '${values}[${var}]'    公共任务池    ${keys}[${var}]
        ...    ELSE IF    '审核中'in '${values}[${var}]'    待办任务    ${keys}[${var}]
    END
    Log Many    ${proposalnolist}
    [Teardown]    Close Browser

GroupCompany
    [Arguments]    ${companycode}    ${Salesman}    ${riskcode}    ${car}    ${PersonGroup}    ${产品}    ${是否两地车}
    Op 投保单菜单单击后    1    # 1 表示为新增报价
    Go DirectSales Business Mode    ${companycode}    ${Salesman}    NONE    1    NONE    NONE    ${产品}
    BaseProposal    ${PersonGroup}    ${car}    ${riskcode}    ${是否两地车}

Fin
    [Arguments]    ${url}    ${username}    ${passwd}
    ${len}=    Get Length    ${proposalnolist}
    ${keys}=    Get Dictionary Keys    ${proposalnolist}
    ${values}=    Get Dictionary Values    ${proposalnolist}
    ${close}=    set variable    False
    FOR    ${var}    IN RANGE    0    ${len}
        run keyword if    '审核通过' =='${values}[${var}]'    登录收付系统    ${url}    ${username}    ${passwd}
        ${close}    run keyword if    '审核通过' =='${values}[${var}]'    set variable    True
        exit for loop if    '审核通过' =='${values}[${var}]'
    END
    sleep    2
    FOR    ${var}    IN RANGE    0    ${len}
        run keyword if    '审核通过' =='${values}[${var}]'    Go 见费出单    ${keys}[${var}]
    END
    run keyword if    '${close}'== 'True'    Close Browser
    Log Many    ${proposalnolist}

BaseProposal
    [Arguments]    ${是否团体}    ${厂牌型号}    ${需要投保险种}    ${是否两地车}
    run keyword if    'group' in '${是否团体}'    GroupOwner
    ...    ELSE    PersonOwner
    differentCar    ${厂牌型号}    ${是否两地车}
    Op Bz Risk Paytaxes    ${是否两地车}
    Bs Risk Type    ${需要投保险种}    ${是否两地车}
    run keyword if    'group'in '${是否团体}'    GroupRelation
    ...    ELSE    PersonRelation
    Op 申请报价后

主险附加险
    [Arguments]    ${pdcode}
    run keyword if    '${pdcode}' in '0317'    Op Bs Risk 新能源主险+附加险
    ...    ELSE    Op Bs Risk 示范条款主险+附加险

批改-退保
    ${len}=    Get Length    ${proposalnolist}
    ${keys}=    Get Dictionary Keys    ${proposalnolist}
    ${values}=    Get Dictionary Values    ${proposalnolist}
    Switch Browser    VHL
    # 一条数据
    FOR    ${var}    IN RANGE    0    ${len}
        ${IsPolicy}=    Start_with    '${values}[${var}]'    '6'    0    1
        run keyword if    ${IsPolicy}== True    退保    ${values}[${var}]    16-退保
        ...    ELSE    log    ${keys}[${var}]
    END
    Log Many    ${proposalnolist}
